// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   BackgroundChooser.java

package presenter;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;

// Referenced classes of package presenter:
//            SongFile

public class BackgroundChooser extends JPanel
    implements ActionListener
{

    public BackgroundChooser()
    {
        update = false;
        change = new JButton("Change Background");
        preview = new JLabel();
        change.addActionListener(this);
        add(change);
        add(preview);
    }

    public boolean isUpdated()
    {
        if(update)
        {
            update = false;
            return true;
        } else
        {
            return false;
        }
    }

    public void setSong(SongFile song)
    {
        this.song = song;
        if(song.hasCustomBackground())
            setBackground(song.getBackground());
        else
            preview = new JLabel();
    }

    public ImageIcon loadImage(String path)
    {
        return new ImageIcon(Toolkit.getDefaultToolkit().getImage(path));
    }

    public void setBackground(String image)
    {
        background = image;
        preview.setIcon(loadImage(image));
        add(preview);
        update = true;
    }

    public String getBackgroundString()
    {
        return background;
    }

    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == change)
        {
            chooser = new JFileChooser(new File("./Backgrounds/"));
            int returnVal = chooser.showOpenDialog(null);
            if(returnVal == 0)
            {
                String path = (new StringBuilder()).append("./Backgrounds/").append(chooser.getSelectedFile().getName()).toString();
                background = path;
                song.setBackground(background);
                setBackground(path);
                update = true;
            }
        }
    }

    private JButton change;
    private JFileChooser chooser;
    private JLabel preview;
    private String background;
    private SongFile song;
    private boolean update;
}
